﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Assist;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using HYRevitCode.FormUtility.ModelessFormControlSuite.ViewLayer;
using HYView;

namespace AdjustInstallationHeight
{
	[Regeneration(RegenerationOption.Manual)]
	[Transaction(TransactionMode.Manual)]
	internal class CmdAdjustDuct : IExternalCommand
	{
		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements)
		{
            CmdAdjustDuct.m_hWndRevit = new HYCodeBase.WinForm.WindowHandle(Process.GetCurrentProcess().MainWindowHandle);
			UIDocument activeUIDocument = cmdData.Application.ActiveUIDocument;
			if (!(activeUIDocument.Document.ActiveView is ViewPlan))
			{
				Result result = SwitchView.SetUsableView((CmdViewType)251, cmdData);
                if (result != Result.Succeeded)
				{
					return result;
				}
			}
			new List<ViewPlan>();
			new List<ElementId>();
			List<FormStructure> lstFormData = new List<FormStructure>();
			BaseNoneSwitchForm baseNoneSwitchForm = new BranchForm("风管", activeUIDocument, CmdAdjustDuct.m_hWndRevit);
			lstFormData = ((BranchForm)baseNoneSwitchForm).LstFormData;
			new LoopMangerNoneSwitch(activeUIDocument, baseNoneSwitchForm, lstFormData, CmdAdjustDuct.m_hWndRevit, null).DoLoopWork();
			return Autodesk.Revit.UI.Result.Succeeded;
		}

        public static HYCodeBase.WinForm.WindowHandle m_hWndRevit;
	}
}
